package com.example.john.startproject_408lwn;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.WrapperListAdapter;

import com.example.john.startproject_408lwn.bean.WeatherInfo;
import com.example.john.startproject_408lwn.iface.WeatherListner;
import com.example.john.startproject_408lwn.model.Weather51Model;
import com.example.john.startproject_408lwn.model.WeatherModel;

public class MainActivity extends AppCompatActivity implements WeatherListner, View.OnClickListener{


    private EditText etcityno;
    private Button btnfind,btnfind2;
    private TextView txeityname;
    private TextView txeitytemp;
    private TextView txeitywd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

    }
    private void init(){
        etcityno = (EditText)findViewById(R.id.editText);
        btnfind = (Button) findViewById(R.id.button);
        btnfind2 = (Button) findViewById(R.id.button2);
        txeityname = (TextView) findViewById(R.id.textView2);
        txeitytemp = (TextView) findViewById(R.id.textView3);
        txeitywd = (TextView) findViewById(R.id.textView4);
        btnfind.setOnClickListener(this);
        btnfind2.setOnClickListener(this);
    }

    @Override
    public void onResponse(WeatherInfo weatherInfo) {
        if(weatherInfo!=null){
            txeityname.setText(weatherInfo.getCity());
            txeitytemp.setText(weatherInfo.getTemp());
            txeitywd.setText(weatherInfo.getWD());
        }
        else{
            txeityname.setText("未知");
        }
    }

    @Override
    public void onFail(String msg) {
        txeityname.setText(msg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button:
                System.out.println("****查询1被按下");
                WeatherModel weatherModel = new WeatherModel();
                weatherModel.getweather(
                        etcityno.getText().toString(),this

                );

                break;
            case R.id.button2:
                System.out.println("****查询2被按下");
                Weather51Model weather51Model = new Weather51Model();
                weather51Model.getweather(
                        etcityno.getText().toString(),this
                );
                break;
            default:
                break;
        }
    }
}
